package com.tjx.common;

import com.tjx.constant.ResultCode;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result() {
    }
    public static  <T> Result<T> ok(){
        return new Result<>(ResultCode.SUCCESS_CODE,"成功",null);
    }
    public static  <T> Result<T> ok(T data){
        return new Result<>(ResultCode.SUCCESS_CODE,"成功",data);
    }
    public static  <T> Result<T> ok(String message,T data){
        return new Result<>(ResultCode.SUCCESS_CODE,message,data);
    }
    public static <T> Result<T> fail (){
        return new Result<>(ResultCode.FAIL_CODE,"失败",null);
    }
    public static <T> Result<T> fail (T data){
        return new Result<>(ResultCode.FAIL_CODE,"失败",data);
    }
    public static <T> Result<T> fail (String message,T data){
        return new Result<>(ResultCode.FAIL_CODE,message,data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';    }
}
